﻿@page "/settings/register"

@using North.Core.Common;
@using North.Core.Entities

@inject ILogger _logger
@inject ISnackbar _snackbar
@inject IHttpContextAccessor _accessor
@inject NavigationManager _navigationManager
@inject AppSetting _appSetting

<AuthorizeView Roles="User">
    <MudStack Spacing="10" Row AlignItems="AlignItems.Center" Class="message_warn">
        <MudImage Src="icons/warn.svg" Width="180" Elevation="0" Class="rounded-lg ma-4" />
        <MudLink Href="/" Color="Color.Warning" Style="font-weight:bold; font-size:34px;">您的权限不足，无法访问</MudLink>
    </MudStack>
</AuthorizeView>
<AuthorizeView Roles="System">
    <MudStack Spacing="6" Style="padding-left:37px; margin-top:20px;" id="page">
        <!-- 是否开放注册 -->
        <MudStack Spacing="2">
            <MudTooltip Text="开启后可通过邮箱注册账户" Placement="Placement.Right">
                <p class="menu_text">开放注册</p>
                </MudTooltip>
            <MudSwitch @bind-Checked="@RegisterSetting.AllowRegister" 
                    Color="Color.Tertiary" style="width:fit-content;"/>
        </MudStack>
        <!-- 用户注册头像尺寸限制 -->
        <MudStack Spacing="2">
            <MudTooltip Text="允许上传的最大头像尺寸" Placement="Placement.Right">
                <p class="menu_text">头像最大尺寸</p>
            </MudTooltip>
            <MudNumericField @bind-Value="@RegisterSetting.MaxAvatarSize" Min="0"
                            HideSpinButtons Margin="Margin.Dense" Adornment="Adornment.End" AdornmentText="MB" 
                            Variant="Variant.Outlined" Style="width:90%; max-width:100px; height:35px;" />
        </MudStack>
        <!-- 验证邮件有效期 -->
            <MudStack Spacing="2">
            <MudTooltip Text="注册后必须在有效期内通过邮件验证账户" Placement="Placement.Right">
            <p class="menu_text">验证邮件有效期</p>
        </MudTooltip>
        <MudNumericField @bind-Value="@RegisterSetting.VerifyEmailValidTime" Min="0"
                         HideSpinButtons Adornment="Adornment.End" AdornmentText="ms" Variant="Variant.Outlined"
                         Margin="Margin.Dense"  Style="width:90%; max-width:140px; height:35px;" />
        </MudStack>
        <MudDivider />
        <!-- 默认是否允许用户调用 API -->
        <MudStack Spacing="2">
            <MudTooltip Text="默认是否允许调用API" Placement="Placement.Right">
                <p class="menu_text">API调用</p>
            </MudTooltip>
            <MudSwitch @bind-Checked="@RegisterSetting.Default.IsApiAvailable"
                    Color="Color.Tertiary" />
        </MudStack>
        <!-- 默认允许上传的图片数量/容量 -->
        <MudStack Spacing="2" Style="width:100%; max-width:240px;">
            <p class="menu_text">最大上传数量/容量</p>
            <MudStack Row Spacing="3">
                <MudNumericField @bind-Value="@RegisterSetting.Default.MaxUploadNums" Min="0"
                                HideSpinButtons Adornment="Adornment.End" AdornmentText="张" Variant="Variant.Outlined"
                                Margin="Margin.Dense" Style="height:35px;" />
                <MudNumericField @bind-Value="@RegisterSetting.Default.MaxUploadCapacity" Min="0"
                                HideSpinButtons Adornment="Adornment.End" AdornmentText="MB" Variant="Variant.Outlined"
                                Margin="Margin.Dense" Style="height:35px;" />
            </MudStack>
        </MudStack>
        <!-- 默认允许上传的图片数量/容量（单次）-->
        <MudStack Spacing="2" Style="width:100%; max-width:240px;">
            <p class="menu_text">最大上传数量/容量（单次）</p>
            <MudStack Row Spacing="3">
                <MudNumericField @bind-Value="@RegisterSetting.Default.SingleMaxUploadNums"
                                 Min="0" Max="@RegisterSetting.Default.MaxUploadNums"
                                 HideSpinButtons Adornment="Adornment.End" AdornmentText="张" Variant="Variant.Outlined"
                                 Margin="Margin.Dense" Style="height:35px;" />
                <MudNumericField @bind-Value="@RegisterSetting.Default.SingleMaxUploadCapacity"
                                 Min="0" Max="@RegisterSetting.Default.MaxUploadCapacity"
                                 HideSpinButtons Adornment="Adornment.End" AdornmentText="MB" Variant="Variant.Outlined"
                                 Margin="Margin.Dense" Style="height:35px;" />
            </MudStack>
        </MudStack>
        <!-- 保存/取消设置 -->
        <MudStack Row Style="width:100%;">
            <MudButton Variant="Variant.Filled" Color="Color.Tertiary" 
                       OnClick="SaveSettings" Disabled="SaveRunning" Style="width:100px;">
                @if (SaveRunning)
                {
                    <MudProgressCircular Style="width:17px; height:17px; margin-right:10px;" Indeterminate/>
                }
                <MudText>保 存</MudText>
            </MudButton>
            <MudButton Variant="Variant.Filled" Color="Color.Error" 
                       OnClick="RestoreSettings" Disabled="RestoreRunning" Style="width:100px;">
                @if (RestoreRunning)
                {
                    <MudProgressCircular Style="width:17px; height:17px; margin-right:10px;" Indeterminate/>
                }
                <MudText>还 原</MudText>
            </MudButton>
        </MudStack>
    </MudStack>
</AuthorizeView>

<style>
    .menu_text {
        font-weight:bold;
    }

    #page {
        overflow: scroll;
        overflow-x: hidden;
        height: calc(100% - 70px);
    }

    #page::-webkit-scrollbar {
        display:none;
    }

    .message_warn {
        width:fit-content;
        height:fit-content;
        left: 0;
        top: 0;
        bottom: 100px;
        right: 0;
        position: absolute;
        margin: auto;
    }
</style>